<?php
require 'sessionInfo.class.php' ;

if (!is_null($_POST["username"])) {
	$username = $_POST["username"];
}

if (!is_null($_POST["password"])) {
	$password = $_POST["password"];
} 

$db = "mymessageboard";
$root = "root";
$password = "root";
$host = "localhost";
$con = mysqli_connect($host, $root, $password);

if (!$con) {
	exit("服务器连接失败");
}

mysqli_select_db($con, $db);
//
$name = $_POST["username"];
$pwd = md5($_POST["password"]);

$userKey = uniqid("uk_",true);

$sql = "INSERT INTO Persons (name, password, ukkey) Values ('".$name."','".$pwd."','".$userKey."')";

$ret = mysqli_query($con, $sql);
if (!$ret) {
	echo "注册失败";
} 

SessionInfo::setLoginInfo("username", $username);
SessionInfo::setLoginInfo("password", $password);
SessionInfo::setLoginInfo("ukkey", $userKey);


$url = "http://localhost:8888/phpdemo/messageboard/";
header('Location: index.php', true);
?>